home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7620 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.3 KB  |  114 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Questions.
  5. Date: 24 Feb 1996 11:40:00 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4gmteg$fed@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 21, 1996 18:30:45 in article <C++ Questions.>,
  15. 'afalgout@ocean.st.usm.edu (Andrew Wilson Falgout)' wrote: 
  16.  
  17.  
  18. >Ok here it goes.  I know I'll probably receive a few flames from showing  
  19. >my lack of knowledge but I need answers. 
  20.  
  21. Sorry, I'm out of matches, so no flames... 
  22.  
  23. >1> What is the Heap exactly?  Is it similar to a stack? Or is it just  
  24. >another word for a pool of memory. 
  25.  
  26. Roughly, it's a memory pool.  Definitely not the stack. 
  27.  
  28. >2> What is the difference between a virtual function and a normal
  29. function. 
  30.  
  31. A virtual function is one that contains one or more definitions 
  32. from which the appropriate one is selected at run time.  A normal 
  33. function, on the other hand, is known at compile time.  A normal 
  34. function is more efficient, although by a very small margin, but 
  35. a virtual function can be more flexible depending on circumstances. 
  36. To really understand virtual functions, you need to be aware of the 
  37. concept of polymorphism as well as other OO topics. A very small 
  38. contrived example illustrates the basics: 
  39.  
  40. Suppose you have objects that are containers for liquids and 
  41. gases, you have defined both to be a kind of a container (in  
  42. C++ lingo Container is a base class) and you have a Fill function  
  43. defined for each object.  To fill a liquid container, the function 
  44. moves it under a faucet, turns on the faucet and shuts it off 
  45. when the liquid level reaches the top.  To fill a gas container, 
  46. you connect it to a gas pipe, turn the valve on, and turn it 
  47. off when the pressure reaches some predetermined level. 
  48.  
  49. Notice that the concept of Fill is the same even though the 
  50. details are different.  If you are writing an assembly line 
  51. routine, without OO, you'd have to have two versions 
  52. of: 
  53.    get a container 
  54.    call its fill function 
  55.    label it 
  56.    check it 
  57.    move it to its destination 
  58.  
  59. With OO, you can write a single procedure that captures 
  60. the assembly line process without needing to know whether 
  61. you're dealing with cans or tanks.  Just call a function 
  62. that performs the above steps on a basic container object. 
  63. The virtual mechanism "knows" which kind of a container 
  64. is currently being processed and automatically selects the 
  65. correct Get(), Fill(), Label(), Check(), and Dispose(). 
  66.  
  67. Without OO, you'd have to code a test procedure something 
  68. like: 
  69.     switch (container_type) 
  70.      { 
  71.         case BOTTLE:    
  72.              FillBottle(); break; 
  73.         case CAN: 
  74.              FillCan() .... 
  75.  
  76.  
  77.  
  78. >3> What is the purpose of precompiler directives? An example would  
  79. >probably help me understand this one better. 
  80.  
  81. Precompiler directives?  Maybe you mean preprocessor directives. 
  82. They are "interpreted" or "evaluated" before the compiler is invoked. 
  83. Typical uses are to define constants and include header files. 
  84.  
  85. #include "header.h" causes the system to insert the text in file 
  86. header.h in the source code at the place where the #include 
  87. directive is located. 
  88.  
  89. #define FOO 5 
  90. causes the preprocessor to substitute the number 5 everywhere 
  91. in your code where you have written FOO.  This way, if you 
  92. need to change the value of FOO, you only have to change 
  93. it in one place and recompile.  This, BTW, is C style and is 
  94. not widely used by C++ programmers as constant variables 
  95. serve a similar function and provide some advantages in 
  96. debugging as well as type-safety. 
  97.  
  98. >4> Is there an easy way to explain Overloading things?  Like Overloading  
  99. >an Operator. 
  100. >5> What is run-time? 
  101. >6> How many different type/kinds of classes are there.  And what's the  
  102. >difference between them? 
  103. >There are many more questions that come to mind but I really don't  
  104. >wish to take up anymore of everyone's time right now.  Thank you for  
  105. >whatever help I get.  And please don't flame a person who wants to learn. 
  106.  
  107. Running out of time.  Your questions indicate that you really should 
  108. consult a text book if you want to know.   
  109. -- 
  110. Pete Grant 
  111. Kalevi, Inc. 
  112. Software Engineering & development
  113.